/**
* 版权声明：厦门睿商网络科技有限公司 版权所有 违者必究
* 日    期：2020-11-11
*/
package com.rzico.picture.service;

import com.rzico.base.BaseMapper;
import com.rzico.base.impl.BaseServiceImpl;
import com.rzico.core.service.SysReportService;
import com.rzico.picture.PictureUtils;
import com.rzico.picture.entity.Picture;
import com.rzico.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.rzico.picture.mapper.PictureMapper;

import java.io.File;

/**
 * <pre>
 * 素材管理业务类
 * </pre>
 *
 * @author Rzico Boot
 * @version 1.0
 */
@Service
public class PictureService extends BaseServiceImpl<Picture, String> {

    @Autowired
    private PictureMapper pictureMapper;

    @Autowired
    private SysReportService sysReportService;

    @Value("${rzico.filePath.windows}")
    private String windowsFilePath;

    @Value("${rzico.filePath.linux}")
    private String linuxFilePath;

    @Override
    public BaseMapper<Picture, String> getMapper() {
        return pictureMapper;
    }

    public int createImage(Integer id,  String logoText) throws Exception{
        Picture picture = pictureMapper.selectByPrimaryKey(id);
        String filePathAndFileName = "";
        if (StringUtils.isNotEmpty(picture.getUrl())){
            String fileName = picture.getUrl().substring(picture.getUrl().lastIndexOf("/")+1, picture.getUrl().length());
            String filePath = "";
            if (System.getProperty("os.name").contains("Windows")) {
                filePath = windowsFilePath;
            } else if (System.getProperty("os.name").contains("Linux")) {
                filePath = linuxFilePath;
            }
            filePathAndFileName = filePath +"/" + fileName;

            File file=new File(filePathAndFileName);
            if (!file.exists())
            sysReportService.fileDownLoad(picture.getUrl(), filePath, fileName);

        }
/*        if (picture.getType() == 0){
            PictureUtils.makeImageTxt(logoText, filePathAndFileName, picture.getPx(), picture.getPy(), picture.getFontSize(), picture.getAlpha(), picture.getAngle(), picture.getDv(), picture.getRw());

        }else if (picture.getType() == 1){

        }else if (picture.getType() == 2){
            PictureUtils.makeRateImage(logoText, filePathAndFileName, picture);
        }*/
        return 1;
    }
}
